<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<body>
<h:form prependId="false">

	<rich:dataTable value="#{actionBean.companies}" var="comp" first="0"
		rows="#{rowspan.calcTotalRows(actionBean.companies)}">
		<f:facet name="header">
			<rich:columnGroup>

				<rich:column breakBefore="true">
					<h:outputText value="Company" />
				</rich:column>
				<rich:column>
					<h:outputText styleClass="headerText" value="Product" />
				</rich:column>
				<rich:column>
					<h:outputText styleClass="headerText" value="Version)" />
				</rich:column>
			</rich:columnGroup>
		</f:facet>



		<rich:subTable value="#{comp.products}" var="prod"
			rowKeyVar="prodKeyVar">


			<rich:subTable value="#{prod.versions}" var="ver"
				rowKeyVar="verKeyVar">

				<rich:column rowspan="#{rowspan.calcCompanyRowspan(comp)}"
					rendered="#{(prodKeyVar eq 0) and (verKeyVar eq 0)}">
                        #{comp.name}
                    </rich:column>

				<rich:column rowspan="#{rowspan.calcProductRowspan(prod)}"
					rendered="#{verKeyVar eq 0}">
                        #{prod.name}
                    </rich:column>

				<rich:column>#{ver.name}</rich:column>

			</rich:subTable>

			<rich:columnGroup rendered="#{empty prod.versions}">

				<rich:column rowspan="#{rowspan.calcCompanyRowspan(comp)}"
					rendered="#{prodKeyVar eq 0}" style="color: green">
                        #{comp.name}
                    </rich:column>
				<rich:column>
	                   #{prod.name}
	               </rich:column>
				<rich:column>
                   NO VERSIONS
               </rich:column>
			</rich:columnGroup>

		</rich:subTable>

		<rich:columnGroup rendered="#{empty comp.products}">
			<rich:column>			
                    #{comp.name}
                    </rich:column>
			<rich:column rendered="#{empty comp.products}">
                    NO PRODUCTS
                    </rich:column>
			<rich:column rendered="#{empty comp.products}">
                    NO VERSIONS
                    </rich:column>
		</rich:columnGroup>


	</rich:dataTable>

	<p>Desired output:</p>
	<table border="true">
		<tr>
			<td rowspan="4">Company A</td>
			<td rowspan="2">Product A0</td>
			<td>Version A0</td>
		</tr>
		<tr>
			<td>Version A1</td>
		</tr>
		<tr>
			<td rowspan="2">Product A1</td>
			<td>Version A3</td>
		</tr>
		<tr>
			<td>Version A4</td>
		</tr>
		<tr>
			<td rowspan="3">Company B</td>
			<td rowspan="2">Product B0</td>
			<td>Version B0</td>
		</tr>
		<tr>
			<td>Version B1</td>
		</tr>
		<tr>
			<td>Product B1</td>
			<td>NO VERSIONS</td>
		</tr>

		<tr>
			<td>Company C</td>
			<td>NO PRODUCTS</td>
			<td>NO VERSIONS</td>
		</tr>
	</table>
</h:form>
</body>
</html>